<?php
class Pageley_Query_Condition_SingleTests extends Pageley_Test_Case {
	
	private $entity;
	
	public function setUp() {
		$string = new Pageley_Domain_Attribute_Basic("string");
		$number = new Pageley_Domain_Attribute_Basic("number");
		$type = new Pageley_Domain_BasicType(
			"Pageley_Commerce",
			"Article",
			new Pageley_Util_ArrayMap(array(
				"name" => $string,
				"price" => $number
			))
		);
		$this->entity = $type->newInstance();
	}
	
	public function testEquals() {
		$condition = new Pageley_Query_Condition_Equals("name", "foo");
		$this->entity->set("name", "foo");
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("name", "bar");
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testNotEquals() {
		$condition = new Pageley_Query_Condition_NotEquals("name", "foo");
		$this->entity->set("name", "foo");
		$this->assertFalse($condition->matches($this->entity));
		$this->entity->set("name", "bar");
		$this->assertTrue($condition->matches($this->entity));
	}
	
	public function testContains() {
		$condition = new Pageley_Query_Condition_Contains("name", "foo");
		$this->entity->set("name", "foobar");
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("name", "bar");
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testIn() {
		$condition = new Pageley_Query_Condition_In("name", 
			new Pageley_Util_ArrayMap(array("foo", "bar")));
		$this->entity->set("name", "foo");
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("name", "bar");
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("name", "baz");
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testGreaterThan() {
		$condition = new Pageley_Query_Condition_GreaterThan("price", 5.0);
		$this->entity->set("price", 5.1);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 4.9);
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testGreaterThanOrEquals() {
		$condition = new Pageley_Query_Condition_GreaterThanOrEquals("price", 5.0);
		$this->entity->set("price", 5.1);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 5.0);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 4.9);
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testLessThan() {
		$condition = new Pageley_Query_Condition_LessThan("price", 5.0);
		$this->entity->set("price", 4,9);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 5.1);
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testLessThanOrEquals() {
		$condition = new Pageley_Query_Condition_LessThanOrEquals("price", 5.0);
		$this->entity->set("price", 4.9);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 5.0);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 5.1);
		$this->assertFalse($condition->matches($this->entity));
	}
	
	
}